﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDM.BF.AdministrationService;
using Sio.Mdm.Server;
using Sio.Mdm.Entities;
using Sio.Mdm.Types;
using IDM.Types;

namespace IDM.BL.AdministrationService
{
    [Service(Name = "TokensService", DefaultInterface = typeof(BF.AdministrationService.ITokensService))]
    public class TokensService: Sio.Mdm.BL.Base.BaseFirebird<Token>, ITokensService
    {
        #region Construction
        public TokensService()
            : base("IDM")
        {
        } 
        #endregion

        #region ITokensService Members

        public Result SelectParent(Token token, Session session)
        {   
            Criteria criteria = new Criteria();
            criteria.Query.SetExpression(new QueryParameter("ID", token.ID));
            
            int parentId = MakeSelectScalar<int>("Tokens", "ParentID", criteria);

            criteria.Query.SetExpression(new QueryParameter("ID", parentId));
            MakeSelectSingle(token, typeof(Token), criteria);

            return null;
        }

        #endregion
    }
}
